import java.util.HashSet;
import java.util.Set;

/**
 * 独特的电子邮件地址
 *
 * @USER: Administrator
 * @DATE: 2024/9/17 下午4:48
 * @VERSION: 1.0.0
 */
public class LC929 {
    public static void main(String[] args) {
        LC929 lc929 = new LC929();
        System.out.println(lc929.numUniqueEmails(new String[]{"test.email+alex@leetcode.com", "test.email@leetcode.com"}));
    }

    public int numUniqueEmails(String[] emails) {
        Set<String> set = new HashSet<>();
        for (String email : emails) {
            String user = email.split("@")[0];
            String domain = email.split("@")[1];
            if (user.indexOf('+') > 0) {
                user = user.substring(0, user.indexOf('+'));
            }
            user = user.replace(".", "");
            set.add(user + "@" + domain);
        }
        return set.size();
    }

}
